<?php
class Web_Action_Helper_LoadEntities extends Zend_Controller_Action_Helper_Abstract
{
	public function predispatch()
	{
		return $this->loadEntities();
	}
	
	public function loadEntities()
	{
		$session = Zend_Registry::get('session');
		$controller = $this->getActionController();
		
		$session = Zend_Registry::get('session');
		
		if (isset($session->userId)){
		
			try {
			
				$mapper = Vs_Factory::mapper( 'User' );
				$user = $mapper->getById( $session->userId );
				
			}catch (Vs_Exception $e){
	        	
				unset( $session->userId );
				
				$controller->getHelper('Log')->exception( $e );
	        	$controller->getHelper('MyFlashMessenger')->addError( $e->getMessage());
	        	
	        	return $controller->getHelper('Redirector')->gotoUrl('/');	
	        } 	
				
			$controller->user = $user;
			$controller->view->user = $user;
			
		}		
			
	}

	

}